<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/common.css" />
		<link rel="stylesheet" type="text/css" href="../../css/my/coiponcenter.css" />
	</head>

	<body>
		<div id="coiponcenter" v-cloak>
			<header class="mui-bar mui-bar-nav">
				<a class="mui-action-back mui-icon mui-icon-arrowleft mui-pull-left"></a>
				<h1 class="mui-title">领券中心</h1>
			</header>
			<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
				<div class="mui-scroll">
					<div class="coupon_list" v-for="list in list">
						<div class="coupon_img">
							<img src="../../images/youhui.png" />
							<div class="coupon_sum">
								<div>￥{{list.offPrice}}</div>
								<div>{{list.description}}</div>
							</div>
						</div>
						<div class="coupon_data">
							<div>{{list.couponName}}</div>
							<div>使用平台:全平台</div>
							<div>有效期:{{list.endDateStr}}</div>
						</div>
						<div class="coupon_use" @tap="receive(list)">
							立即领取
						</div>
					</div>
					<div></div>
				</div>
			</div>
			<!--领取成功-->
			<!--md_show-->
			<div class="success" :class="{md_show:showMask}">
				<div class="md_content">
					<div class="success_img"><img src="../../images/checked.png" /></div>
					<div class="success_text">领取成功</div>
					<div class="gocoipon"><button type="button" class="mui-btn mui-btn-danger" @tap="immediately">立即去使用</button></div>
					<div class="close" @tap="showMask = false"><img src="../../images/close.png" /></div>
				</div>
			</div>
			<div class="mui-backdrop">
			</div>

			<div class="nocoupon">
				你暂时没有可用的优惠券
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/libs/zepto.js"></script>
		<script src="../../js/libs/vue.js"></script>
		<script src="../../js/common.js"></script>
		<script type="text/javascript">
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto: true,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			})

			var coupon = new Vue({
				el: '#coiponcenter',
				data: {
					imgCommonUrl: common.imageUrl,
					pageNum: 1,
					list: [],
					showMask: false
				},
				methods: {
					receive: function(data) {
						common.ajax('/coupon/p/m/coupon/receive/' + data.couponId, {

						}, function(data) {
							if(data.code == 1) {
								coupon.showMask = true
								var list = plus.webview.getWebviewById('../my/coupon.html')
								mui.fire(list, 'reloads');
							} else {
								if(data.resultMsg) {
									common.toast(data.resultMsg)
								}
							}
						})
					},
					immediately: function() {
						var list = plus.webview.getWebviewById("ylindex.html")
						mui.fire(list, 'gohome');
						var wvs, self, launch;
						wvs = plus.webview.all();
						self = plus.webview.currentWebview();
						launch = plus.webview.getLaunchWebview();
						for(var i = 0, len = wvs.length; i < len; i++) {
							if(wvs[i].getURL() == launch.getURL() || wvs[i].id == 'ylindex.html' || wvs[i].id == 'home.html' || wvs[i].id == 'classify.html' || wvs[i].id == 'special.html' || wvs[i].id == 'shopping.html' || wvs[i].id == 'my.html' || wvs[i].id == '../special/specialregion.html') {
								continue;
							}
							wvs[i].close();
						}
					}
				}
			})

			function pullupRefresh() {
				$('.mui-pull-bottom-pocket').css('display', 'block !important')
							$('.nocoupon').hide()
				common.ajax('/coupon/wap/couponCenter/couponMore/shop', {
					curPageNO: coupon.pageNum++,
				}, function(data) {
					if(data.code == 1) {
						console.log(data.data)
						if(coupon.pageNum > data.data.pageCount) {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
						} else {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh();
						}
						coupon.list = coupon.list.concat(data.data.list)
						if(coupon.list.length <= 0) {
							$('.mui-pull-bottom-pocket').css('display', 'none !important')
							$('.nocoupon').show()
						} else {
							$('.mui-pull-bottom-pocket').css('display', 'block !important')
							$('.nocoupon').hide()
						}
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh();
						if(data.resultMsg) {
							common.toast(data.resultMsg)
						}
					}
				}, true, 'get')
			}
		</script>
	</body>

</html>